package com.yungu.swift.socket.component;

import com.yungu.swift.socket.push.model.PushContent;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by Administrator on 2018/3/20 0020.
 */
public class PushContentMap {
    /**
     * 单例模式
     */
    private static volatile PushContentMap INSTANCE;

    /**
     * 用户可能在不同时间不同状态操作内容map，但不会出现同时操作同一个的情况，不需要加锁
     */
    private Map<String, PushContent> cache = new ConcurrentHashMap<>();

    private PushContentMap() {
    }

    public static PushContentMap getInstance() {
        if (INSTANCE == null) {
            synchronized (PushContentMap.class) {
                if (INSTANCE == null) {
                    INSTANCE = new PushContentMap();
                }
            }
        }
        return INSTANCE;
    }

    /**
     * @param pushUuid
     * @param pushContent
     * @return
     */
    public void put(String pushUuid, PushContent pushContent) {
        cache.put(pushUuid, pushContent);
    }

    /**
     * @param pushUuid
     */
    public void remove(String pushUuid) {
        cache.remove(pushUuid);
    }

    /**
     * @param pushUuid
     */
    public boolean containsKey(String pushUuid) {
        return cache.containsKey(pushUuid);
    }

    /**
     *
     */
    public int size() {
        return cache.size();
    }

}
